<?php 

include 'util.php';

//check if user is logged in
session_name('login');
session_start();
if($_SESSION['username'] == null)
{
	//redirect back to home
	header("location: /home.php");
}


if(isset($_POST['addCardSubmit']))
{
	//sanitize
	$cardNumber = $_POST['cardNumber'];
	$cardType = $_POST['cardType'];
	$expDate = $_POST['expDate'];
	
	$userId = $_SESSION['userId'];
	//query for an active cart for user
	$dbConnection = getMySqlConnection();
	
	$query = "INSERT INTO payment VALUES (NULL, $userId, '$cardType', '$cardNumber', '$expDate');";
	
	$result = $dbConnection->query($query);
	
	header("location: /checkoutInfo.php");
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
               
<html>
<head>
	<link rel="StyleSheet" type="text/css" href="css/tcaparrel.css">
	<link rel="StyleSheet" href="css/header.css" type="text/css">
	<script type="text/javascript" src="javascript/tcaparrel.js">
	</script>
</head>

<body >
<div class="contentWrapper">
	<div class="header">
		<?php 
		session_name('login');
		session_start();
		if(isset($_SESSION['username']))
		{
			include('loggedInUserHeader.php');
		}
		else
		{
			include ('loginformheader.php');
		}
		?>
	</div>
	
	<div class="menubarContentWrapper">
			<div class="menubar">
				<div class="menuItem" onclick="sweatshirts_click()"><label style="cursor: inherit">SweatShirts</label></div>
				<div class="menuItem" onclick="hats_click()"><label style="cursor: inherit">Hats</label></div>
				<div class="menuItem" onclick="tshirts_click()"><label style="cursor: inherit">T-Shirts</label></div>
				<div class="menuItem" onclick="pants_click()"><label style="cursor: inherit">Pants</label></div>
			</div>
	</div>
	
	<div class="body">
		<h1>Add a New Card</h1>
		
		<form action="addNewCard.php" method="post">
			<label>Card Type: </label>
			<select name="cardType">
				<option value="Visa">Visa</option>
				<option value="MC">MasterCard</option>
				<option value="Disc">Discover</option>
			</select>
			<br/>
			<label>Card Number: </label><input type="text" name="cardNumber" />
			<br/>
			<label>Exp Date:</label><input type="text" name="expDate" />
			<br/>
			
			<input type="submit" name="addCardSubmit" value="Submit" />
		</form>
	</div>
	
	<div class="footer"></div>
</div>
</body>

</html>